class Partner < ApplicationRecord
  # 定义往来单位类型， 0：客户， 1：供应商， 2：客户和供应商
  enum partner_type: { 客户: 0, 供应商: 1 }

  scope :customers, -> {where(type: 'Customer') } # Partner.customers
  scope :suppliers, -> {where(type: 'Supplier') } #Parnter.suppliers

  belongs_to :partner_category
  has_many :contacts

  accepts_nested_attributes_for :contacts

  #====== validations =========
  validates_presence_of :code,:name, :type, :partner_category_id
  validates_uniqueness_of :code
  # validates :partner_type, :inclusion => { :in => :partner_type }

end
